<? if ($c = stack('name')) {

//	$d = component_data($c); 
	$s = component_settings($c);

	ob_start();
	
	if (sizeof($DIAGS)) {
		?><script type="text/javascript">jQuery(function($) {	$(".diags").fadeTo(10000, 0).slideUp(500) });</script><?
		?><div class="diags"><p><?=implode("</p><p>", $DIAGS)?></p></div><?
	}
	
	?><form action="" method="post" enctype="multipart/form-data">

		<table>
		
		<? if (sizeof($d = component_data($c))) {

			foreach($d as $id => $a) {
			
				switch($a['kind']) {
					
					case 1: //text field

						?><tr>
						   <td class="b-field-name">
							  <label for="field<?=$id?>"><?=$a['title']?></label>
						   </td>
						   <td class="b-field-value"><input type="text" name="field<?=$id?>" id="field<?=$id?>" class="contact-input" value="<?=$_POST["field$id"]?>" /></td>
						</tr><?

						break;

					case 2: //textarea field

						?><tr>
						   <td class="b-field-name">
							  <label for="field<?=$id?>"><?=$a['title']?></label>
						   </td>
						   <td class="b-field-value"><textarea name="field<?=$id?>" id="field<?=$id?>" class="contact-input" rows="10"><?=$_POST["field$id"]?></textarea></td>
						</tr><?

						break;

					case 3: //checkboxes field
					
						?><tr>
						   <td class="b-field-name">
							  <label><?=$a['title']?></label>
						   </td>
						   <td class="b-field-value">
								<? foreach($a['options'] as $k => $v) { ?>
							   	<div><input type="checkbox" name="field<?=$id?>[]" value="<?=$k?>" /><span><?=$v?></span></div>
								<? } ?>
								<input type="text" name="field<?=$id?>_other" class="contact-input" /></div>
						   </td>
						</tr><?
						
						break;
						
					case 4: //file upload

						?><tr>
						   <td class="b-field-name">
							  <label for="field<?=$id?>"><?=$a['title']?></label>
						   </td>
						   <td class="b-field-value"><input type="file" name="field<?=$id?>" id="field<?=$id?>" class="contact-input" /></td>
						</tr><?
					
						break;
				}
			} 
		} ?>

		</table>
		<input type="hidden" name="check" value="<?=$s['check']?>" />
		<p><input type="submit" name="send_form" value="<?=$s['form_send']?>" /></p>
		</form>
	<?

		$form = ob_get_clean();
		
		$html = (strpos($s['caption'], '{form}') !== false) ? str_replace('{form}', $form, $s['caption']) : $s['caption'].$form;
		
	?><?=$html?><?
	
	unstack();
} ?>